﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PMG.model;
using PMG.data;
using PMG.data.Tool;
using System.Text;
using System.IO;

public partial class ADMINSurvey_SurveyExcel : System.Web.UI.Page
{

    #region 注入对象
    private DaoACCOUNT _DaoACCOUNT;
    public DaoACCOUNT DaoACCOUNT
    {
        get { return _DaoACCOUNT; }
        set { _DaoACCOUNT = value; }
    }

    private DaoANSWER _DaoANSWER;
    public DaoANSWER DaoANSWER
    {
        get { return _DaoANSWER; }
        set { _DaoANSWER = value; }
    }

    private DaoOPTIONS _DaoOPTIONS;
    public DaoOPTIONS DaoOPTIONS
    {
        get { return _DaoOPTIONS; }
        set { _DaoOPTIONS = value; }
    }

    private DaoQUESTION _DaoQUESTION;
    public DaoQUESTION DaoQUESTION
    {
        get { return _DaoQUESTION; }
        set { _DaoQUESTION = value; }
    }
    #endregion


    protected void Page_Load(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        IList<QUESTION> qlist = DaoQUESTION.SearchByWhereOrder("QUESTIONNAIREID=1", "ORDERIDX", true);
        IList<OPTIONS> oplist = DaoOPTIONS.SearchByWhereOrder("QUESTIONNAIREID=1", "Id", true);
        string strSql = "";
        int col = 0;
        sb.Append("<TABLE borderColor=#808080 border=1>");
        sb.Append("<THEAD>");
        sb.Append("<TR>");
        sb.Append("<TD rowspan=2>姓名</TD>");
        sb.Append("<TD rowspan=2>公司</TD>");
        sb.Append("<TD rowspan=2>电话</TD>");
        for (int i = 0; i < qlist.Count; i++)
        {
            col = DaoOPTIONS.GetRecordCount("QUESTIONID = " + qlist[i].Id);
            sb.Append("<TD colspan=" + col + ">" + qlist[i].QUESTION1 + "</TD>");
            
        }
        sb.Append("</TR>");
        sb.Append("<TR>");
        for (int i = 0; i < oplist.Count; i++)
        {
            sb.Append("<TD >" + oplist[i].LABEL + "</TD>");
            strSql += ",dbo.fGetAnwserNum(" + oplist[i].Id + ",[id])";
        }
        sb.Append("</TR>");
        sb.Append("</THEAD>");
        sb.Append("<TBODY>");

        strSql = "select fullname,Company,tel " + strSql + " from account";
        DataSet ds = SqlHelper.GetDatasetSql(strSql);
        if (ds != null)
        {
            DataTable dt = ds.Tables[0];
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                sb.Append("</TR>");
                sb.Append("<TD>" + dt.Rows[j][0]+ "</TD>");
                sb.Append("<TD>" + dt.Rows[j][1] + "</TD>");
                sb.Append("<TD>" + dt.Rows[j][2] + "</TD>");
                for (int x = 0; x < oplist.Count; x++)
                {
                    sb.Append("<TD >" + dt.Rows[j][x+3] + "</TD>");
                }
                sb.Append("</TR>");
            }
        
        }
        sb.Append("</TBODY></TABLE>");
        labExcel.Text = sb.ToString();
    }
}
